package geodata;

/**
 * @author Sean Freitag
 * Parameters for modeling a closed circuit of bores
 */
@SuppressWarnings("serial")
public class BorefieldData extends GeoData {
	
	/**
	 * BuildingData
	 */
	private BuildingData building;
	
	/**
	 * GeologicalData
	 */
	private GeologicalData geo;
	
	/**
	 * BoreData
	 */
	private BoreData bore;
	
	/**
	 * Creates a new BorefieldData from 3 other GeoData's
	 * @param building
	 * BuildingData
	 * @param geo
	 * GeologicalData
	 * @param bore
	 * BoreData
	 */
	public BorefieldData(BuildingData building, GeologicalData geo, BoreData bore){
		this.building = building;
		this.geo = geo;
		this.bore = bore;
	}
	
	/**
	 * @return
	 * Kavenaugh's equation for loop length of heating
	 */
	public double heatingLength(){
		
		
		
		
		
		double part1 = building.getFieldByName("Net Average Heat Transfer").getValue().doubleValue() * Rga();
		double part2 = building.getFieldByName("Heating Block Load").getValue().doubleValue() - 3.413 * building.getFieldByName("Power Input Heating").getValue().doubleValue();
		double part3 = bore.getFieldByName("Thermal Resistance").getValue().doubleValue() + PLFm() * Rgm() + Rgd() * Fsc();
		
		
		double top = part1 + part2 * part3;
		
		
		
		
		double bottom = geo.getFieldByName("Ground Temp").getValue().doubleValue() - ( (building.getFieldByName("Heat Pump Inlet").getValue().doubleValue() + building.getFieldByName("Heat Pump Outlet").getValue().doubleValue()) / 2 ) - temperaturePenalty();
		
		return top / bottom;
	}
	
	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double Fsc() {
		return 1;
	}

	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double Rgd() {
		return 1;
	}

	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double PLFm() {
		return 1;
	}

	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double Rgm() {
		return 1;
	}

	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double Rga() {
		return 1;
	}

	/**
	 * @return
	 * Kavenaugh's equation for loop length of cooling
	 */
	public double coolingLength(){
		
		
		
		
		
		
		
		
		
		double part1 = building.getFieldByName("Net Average Heat Transfer").getValue().doubleValue() * Rga();
		double part2 = building.getFieldByName("Cooling Block Load").getValue().doubleValue() - 3.413 * building.getFieldByName("Power Input Cooling").getValue().doubleValue();
		double part3 = bore.getFieldByName("Thermal Resistance").getValue().doubleValue() + PLFm() * Rgm() + Rgd() * Fsc();
		
		double top = part1 + part2 * part3;
		double bottom = geo.getFieldByName("Ground Temp").getValue().doubleValue() - ( (building.getFieldByName("Heat Pump Inlet").getValue().doubleValue() + building.getFieldByName("Heat Pump Outlet").getValue().doubleValue()) / 2 ) - temperaturePenalty();
		
		return top / bottom;
	}
	
	/**
	 * @return
	 * The number of bores required to satisfy the heating length
	 */
	public int heatingBores(){
		return (int)Math.ceil(heatingLength()/bore.getFieldByName("Bore Depth").getValue().doubleValue());
	}
	
	/**
	 * @return
	 * The number of bores required to satisfy the cooling length
	 */
	public int coolingBores(){
		return (int)Math.ceil(coolingLength()/bore.getFieldByName("Bore Depth").getValue().doubleValue());
	}

	/**
	 * @see geodata.GeoData#setMetric()
	 */
	public void setMetric() {
		building.setMetric();
		geo.setMetric();
		bore.setMetric();
	}

	/**
	 * @see geodata.GeoData#setStandard()
	 */
	public void setStandard() {
		building.setStandard();
		geo.setStandard();
		bore.setStandard();
	}
	
	/**
	 * @return
	 * Ashrae voodoo that will replaced in a future iteration
	 */
	private double temperaturePenalty(){
		return 0;
	}
	
}
